local zhenjun = fk.CreateSkill {
  name = "lingling__zhenjun",
}

Fk:loadTranslationTable{
  ["lingling__zhenjun"] = "镇军",
  [":lingling__zhenjun"] = "每回合每种牌名限一次，当一名角色成为伤害类锦囊牌的唯一目标后，你可以摸一张牌，然后若你手牌多于其，你交给其一张牌。",

  ["#lingling__zhenjun-self"] = "镇军：你可以摸一张牌",
  ["#lingling__zhenjun-invoke"] = "镇军：你可以摸一张牌，然后交给 %dest 一张牌",
  ["#lingling__zhenjun-give"] = "镇军：请交给 %dest 一张牌",
}

zhenjun:addEffect(fk.TargetConfirmed, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zhenjun.name) and
      data.card.is_damage_card and data.card:isCommonTrick() and data:isOnlyTarget(target) and
      not table.contains(player:getTableMark("lingling__zhenjun-turn"), data.card.trueName)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if target == player then
      return room:askToSkillInvoke(player, {
        skill_name = zhenjun.name,
        prompt = "#lingling__zhenjun-self",
      })
    elseif room:askToSkillInvoke(player, {
      skill_name = zhenjun.name,
      prompt = "#lingling__zhenjun-invoke::"..target.id,
    }) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addTableMark(player, "lingling__zhenjun-turn", data.card.trueName)
    player:drawCards(1, zhenjun.name)
    if target == player or player:getHandcardNum() <= target:getHandcardNum() or player.dead or target.dead then return end
    local card = room:askToCards(player, {
      skill_name = zhenjun.name,
      min_num = 1,
      max_num = 1,
      prompt = "#lingling__zhenjun-give::"..target.id,
      include_equip = true,
      cancelable = false,
    })[1]
    room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonGive, zhenjun.name, nil, true, player)
  end,
})

return zhenjun
